﻿using System;
using System.Windows;
using System.Collections.ObjectModel;
using System.IO.IsolatedStorage;
using WorkoutTracker.Model;

namespace WorkoutTracker.ViewModelNameSpace
{
    public class WorkoutViewModel
    {
        public Workout WorkoutToHandle { get; set; }

        public void CreateNewWorkout()
        {
            WorkoutToHandle = new Workout() { Name = "Input name" };
        }

        public void GetWorkout(string name)
        {
            IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
            if (settings.Contains(name))
            {
                WorkoutToHandle = (Workout) settings[name];
            }
            else
            {
                MessageBox.Show("This workout \"" + name +"\" has not been added yet!");                
            }
        }

        public void ModfiyWorkout()
        {
            IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
            settings[WorkoutToHandle.Name] = WorkoutToHandle.GetCopy();
        }

        public void SaveWorkout()
        {
            IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;

            if (settings.Contains(WorkoutToHandle.Name))
            {
                MessageBox.Show("This workout has already been added!");
            }
            else
            {
                settings.Add(WorkoutToHandle.Name, WorkoutToHandle.GetCopy());
                MessageBox.Show("Add new workout successfully!");
            }
        }

    }
}
